import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class CopyFile {
    public static void main(String[] args) throws IOException {
        File firstFile=new File("D:/刘景景的测试文件夹");
        File secondFile=new File("D:/古振新的测试文件夹");
        if (!(secondFile.exists())){
            secondFile.mkdirs();
        }
        copyBox(firstFile,secondFile);
        System.out.println("复制完毕");
    }
    public static void copyBox(File firstFile,File secondFile) throws IOException {
        File[] arr=firstFile.listFiles();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].isFile()){
                File sCopyFile=new File(secondFile,arr[i].getName());
                RandomAccessFile firstRAF=new RandomAccessFile(arr[i],"rw");
                RandomAccessFile secondRAF=new RandomAccessFile(sCopyFile,"rw");
                byte[] data=new byte[1024];
                int len=-1;
                while ((len=firstRAF.read(data))!=-1){
                    secondRAF.write(data,0,len);
                }
                firstRAF.close();
                secondRAF.close();
            }else {
                File sCopyFile=new File(secondFile,arr[i].getName());
                sCopyFile.mkdirs();
                copyBox(arr[i],sCopyFile);
            }
        }
    }
}
